package util;

public class Timer {
	private double max;
	private double current;
	private boolean cont;
	private double lowerBound;
	private double inc;
	private boolean stopped = true;


	public Timer(double max, boolean cont) {
		this.max = max;
		this.cont = cont;
		inc = 1;
		current = max;

	}

	public Timer(double lowerBound, double max, double inc, boolean cont) {
		this.max = max;
		this.cont = cont;
		this.lowerBound = lowerBound;
		this.inc = inc;
	}

	public void count() {

		count(inc);

	}

	public void count(double inc) {
		if(! stopped) {
			current = Math.max(lowerBound, current - inc);
			if(cont && current == lowerBound) 
				current = max;
		}
	}

	public boolean ready() {
		return current == lowerBound && ! stopped;
	}

	public void reset() {
		current = max;
	}

	public double getValue() {
		return current;
	}

	public void stop() {
		stopped = true;
	}
	
	public boolean isStopped() {
		return stopped;
	}
	
	public void start() {
		stopped = false;
		reset();
	}

}
